package sk.stuba.fiit.foo07.genex.gui;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.ArrayList;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JSeparator;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.JTextPane;
import javax.swing.SwingConstants;
import javax.swing.WindowConstants;
import javax.swing.border.TitledBorder;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;

import sk.stuba.fiit.foo07.genex.beans.Category;
import sk.stuba.fiit.foo07.genex.beans.Question;
import sk.stuba.fiit.foo07.genex.beans.QuestionPoints;
import sk.stuba.fiit.foo07.genex.beans.Test;
import sk.stuba.fiit.foo07.genex.common.ConnectionHelper;
import sk.stuba.fiit.foo07.genex.common.ResourceHelper;
import sk.stuba.fiit.foo07.genex.dao.CategoryDao;
import sk.stuba.fiit.foo07.genex.dao.CategoryDaoDerby;
import sk.stuba.fiit.foo07.genex.dao.TestDao;
import sk.stuba.fiit.foo07.genex.dao.TestDaoDerby;
import sk.stuba.fiit.foo07.genex.dao.UserDaoDerby;

/**
 * This code was edited or generated using CloudGarden's Jigloo SWT/Swing GUI
 * Builder, which is free for non-commercial use. If Jigloo is being used
 * commercially (ie, by a corporation, company or business for any purpose
 * whatever) then you should purchase a license for each developer using Jigloo.
 * Please visit www.cloudgarden.com for details. Use of Jigloo implies
 * acceptance of these licensing terms. A COMMERCIAL LICENSE HAS NOT BEEN
 * PURCHASED FOR THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED LEGALLY FOR
 * ANY CORPORATE OR COMMERCIAL PURPOSE.
 */
public class NewTestDialog extends javax.swing.JDialog {
    /**
     * 
     */
    private static final long serialVersionUID = 8403446546144184388L;

    private ResourceHelper resHelp;
    private GenexTableModel genexModel;
    private NewTestTableModel model;
    private JLabel jLblCategory;
    private JLabel jLabel7;
    private Category actualTestCategory;
    private Test test;
    private GenexGUI genex;

    private JTextField jTxtSubject;
    private JTextField jTxtName;
    private JLabel jLabel6;
    private JLabel jLabel5;
    private JScrollPane jScrHint;
    private JTextPane jTxtHint;
    private JTable jTblQuestions;
    private JLabel jLabel2;
    private JLabel jLabel3;
    private JLabel jLabel4;
    private JButton jBtnAddQuestion;
    private JButton jBtnEditQuestion;
    private JButton jBtnRemove;
    private JLabel jLblDiff;
    private JLabel jLblPointsCount;
    private JLabel jLblQuestionCount;
    private JLabel jLabel1;
    private JButton jBtnReorder;
    private JButton jBtnItemsDown;
    private JButton jBtnItemsUp;
    private JSeparator jSeparator2;
    private JButton jBtnOK;
    private JButton jBtnCancel;
    private JScrollPane jScrQuestions;
    private JLabel jLblQuestions;
    private JSeparator jSeparator1;
    private boolean flag = false;

    public NewTestDialog() {
        // kokotina, ktoru treba
    }

    public NewTestDialog(GenexGUI frame, NewTestTableModel model,
            GenexTableModel genexModel, Category testCat, Test test) {
        super();

        resHelp = new ResourceHelper();
        this.model = model;
        this.genexModel = genexModel;
        this.actualTestCategory = testCat;
        this.test = test;
        this.genex = frame;

        initGUI();

        jLblCategory.setText(this.actualTestCategory.getName());

        if (test != null) {
            jTxtName.setText(test.getName());
            jTxtSubject.setText(test.getSubject());
            setTitle("Upraviť test");
        }

        setStat();
        hint("Info: Počet bodov môžete upraviť kliknutím na danú bunku.");
    }

    private void setStat() {
        jLblQuestionCount.setText(new Integer(model.getQuestionCount())
                .toString());
        jLblPointsCount.setText(new Float(model.getPointsSum()).toString());
        jLblDiff.setText(new Float(model.getAverageDiff()).toString());
    }

    private void initGUI() {
        try {
            {
                getContentPane().setLayout(null);
                this.setTitle("Nový test");
                this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
                this.setResizable(false);
                this.setLocationByPlatform(true);
                this.addWindowListener(new WindowAdapter() {

                    @Override
                    public void windowClosed(WindowEvent e) {
                        genex.setNewTestButton(true);
                        genex.updateTestTree();
                        super.windowClosed(e);
                    }

                    @Override
                    public void windowOpened(WindowEvent e) {
                        genex.setNewTestButton(false);
                        super.windowOpened(e);
                    }
                });
                this.addComponentListener(new ComponentListener() {
                    @Override
                    public void componentHidden(ComponentEvent e) {
                        genex.setNewTestButton(true);
                        if (!flag)
                            genex.updateTestTree();
                    }

                    @Override
                    public void componentMoved(ComponentEvent e) {
                    }

                    @Override
                    public void componentResized(ComponentEvent e) {
                    }

                    @Override
                    public void componentShown(ComponentEvent e) {
                        genex.setNewTestButton(false);
                    }

                });
                this.setModalityType(ModalityType.MODELESS);
                {
                    jScrHint = new JScrollPane();
                    getContentPane().add(jScrHint);
                    jScrHint.setBounds(12, 12, 537, 64);
                    {
                        jTxtHint = new JTextPane();
                        jScrHint.setViewportView(jTxtHint);
                        jTxtHint.setBackground(GenexGUI.COMB1_BACKGROUND_COLOR);
                        jTxtHint.setForeground(GenexGUI.COMB1_FOREGROUND_COLOR);
                        jTxtHint.setEditable(false);
                    }
                }
                {
                    jSeparator1 = new JSeparator();
                    getContentPane().add(jSeparator1);
                    jSeparator1.setBounds(12, 82, 535, 10);
                }
                {
                    jLblQuestions = new JLabel();
                    getContentPane().add(jLblQuestions);
                    jLblQuestions.setText("Otázky testu");
                    jLblQuestions.setBounds(12, 140, 126, 14);
                    jLblQuestions.setForeground(new java.awt.Color(100, 0, 0));
                }
                {
                    jScrQuestions = new JScrollPane();
                    getContentPane().add(jScrQuestions);
                    jScrQuestions.setBounds(12, 160, 537, 255);
                    {
                        jTblQuestions = new JTable();
                        jScrQuestions.setViewportView(jTblQuestions);
                        jScrQuestions.getViewport().setBackground(
                                new Color(255, 255, 240));
                        jTblQuestions.setModel(model);
                        jTblQuestions.setBackground(new Color(255, 255, 240));
                        jTblQuestions.setShowGrid(false);
                        jTblQuestions.getColumnModel().getColumn(0)
                                .setPreferredWidth(20);
                        jTblQuestions.getColumnModel().getColumn(1)
                                .setPreferredWidth(300);
                        jTblQuestions.getColumnModel().getColumn(2)
                                .setPreferredWidth(20);
                        jTblQuestions.getColumnModel().getColumn(3)
                                .setPreferredWidth(80);
                        jTblQuestions.getColumnModel().getColumn(3)
                                .setCellRenderer(new ProgressCellRenderer());
                        jTblQuestions.getColumnModel().getColumn(4)
                                .setPreferredWidth(70);
                        jTblQuestions.getModel().addTableModelListener(
                                new TableModelListener() {
                                    @Override
                                    public void tableChanged(
                                            TableModelEvent arg0) {
                                        setStat();
                                    }

                                });
                        jTblQuestions.addMouseListener(new MouseAdapter() {
                            @Override
                            public void mouseClicked(MouseEvent evt) {
                                int sel = jTblQuestions.getSelectedRow();
                                if (sel == -1)
                                    return;
                                if (evt.getClickCount() == 2)
                                    editQuestion();
                            }

                        });
                        jTblQuestions.getSelectionModel()
                                .addListSelectionListener(
                                        new ListSelectionListener() {
                                            @Override
                                            public void valueChanged(
                                                    ListSelectionEvent e) {
                                                int sel = jTblQuestions
                                                        .getSelectedRow();
                                                if (sel == -1)
                                                    return;
                                                hint(model.getQuestion(sel)
                                                        .getText());
                                            }

                                        });
                    }
                }
                {
                    jBtnCancel = new JButton();
                    getContentPane().add(jBtnCancel);
                    jBtnCancel.setText("Cancel");
                    jBtnCancel.setBounds(463, 553, 86, 21);
                    jBtnCancel.setMnemonic(java.awt.event.KeyEvent.VK_C);
                    jBtnCancel.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            jBtnCancelActionPerformed(evt);
                        }
                    });
                }
                {
                    jBtnOK = new JButton();
                    getContentPane().add(jBtnOK);
                    jBtnOK.setText("OK");
                    jBtnOK.setBounds(372, 553, 86, 21);
                    jBtnOK.setMnemonic(java.awt.event.KeyEvent.VK_O);
                    jBtnOK.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            jBtnOKActionPerformed(evt);
                        }
                    });
                }
                {
                    jSeparator2 = new JSeparator();
                    getContentPane().add(jSeparator2);
                    jSeparator2.setBounds(12, 539, 537, 8);
                }
                {
                    jBtnItemsUp = new JButton();
                    getContentPane().add(jBtnItemsUp);
                    jBtnItemsUp.setIcon(new ImageIcon(new ResourceHelper()
                            .getResourceBytes("/icons/uparrow.png")));
                    jBtnItemsUp.setActionCommand("Hore");
                    jBtnItemsUp
                            .setHorizontalTextPosition(SwingConstants.CENTER);
                    jBtnItemsUp.setVerticalTextPosition(SwingConstants.BOTTOM);
                    jBtnItemsUp.setToolTipText("Hore");
                    jBtnItemsUp.setBounds(12, 421, 21, 21);
                    jBtnItemsUp.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            jBtnItemsUpActionPerformed(evt);
                        }
                    });
                }
                {
                    jBtnItemsDown = new JButton();
                    getContentPane().add(jBtnItemsDown);
                    jBtnItemsDown.setIcon(new ImageIcon(new ResourceHelper()
                            .getResourceBytes("/icons/downarrow.png")));
                    jBtnItemsDown.setActionCommand("Dole");
                    jBtnItemsDown
                            .setHorizontalTextPosition(SwingConstants.CENTER);
                    jBtnItemsDown
                            .setVerticalTextPosition(SwingConstants.BOTTOM);
                    jBtnItemsDown.setToolTipText("Dole");
                    jBtnItemsDown.setBounds(38, 421, 21, 21);
                    jBtnItemsDown.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            jBtnItemsDownActionPerformed(evt);
                        }
                    });
                }
                {
                    jBtnReorder = new JButton();
                    getContentPane().add(jBtnReorder);
                    jBtnReorder.setIcon(new ImageIcon(new ResourceHelper()
                            .getResourceBytes("/icons/refresh.png")));
                    jBtnReorder.setActionCommand("Preusporiada\u0165");
                    jBtnReorder
                            .setHorizontalTextPosition(SwingConstants.CENTER);
                    jBtnReorder.setVerticalTextPosition(SwingConstants.BOTTOM);
                    jBtnReorder.setToolTipText("Preusporiada\u0165");
                    jBtnReorder.setBounds(70, 421, 21, 21);
                    jBtnReorder.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            jBtnReorderActionPerformed(evt);
                        }
                    });
                }
                {
                    jLabel1 = new JLabel();
                    getContentPane().add(jLabel1);
                    jLabel1.setBounds(12, 453, 537, 74);
                    TitledBorder border = BorderFactory
                            .createTitledBorder("Výsledný test");
                    border.setTitleColor(new Color(49, 106, 196));
                    jLabel1.setBorder(border);
                }
                {
                    jLabel2 = new JLabel();
                    getContentPane().add(jLabel2);
                    jLabel2.setText("Po\u010det otázok");
                    jLabel2.setBounds(29, 475, 134, 14);
                    jLabel2.setForeground(new java.awt.Color(100, 0, 0));
                }
                {
                    jLabel3 = new JLabel();
                    getContentPane().add(jLabel3);
                    jLabel3.setText("Po\u010det bodov");
                    jLabel3.setBounds(29, 501, 134, 14);
                    jLabel3.setForeground(new java.awt.Color(100, 0, 0));
                }
                {
                    jLabel4 = new JLabel();
                    getContentPane().add(jLabel4);
                    jLabel4.setText("Priemerná zlo\u017eitos\u0165 testu");
                    jLabel4.setBounds(294, 473, 166, 14);
                    jLabel4.setForeground(new java.awt.Color(100, 0, 0));
                }
                {
                    jLblQuestionCount = new JLabel();
                    getContentPane().add(jLblQuestionCount);
                    jLblQuestionCount.setText("0");
                    jLblQuestionCount.setBounds(192, 475, 38, 14);
                    jLblQuestionCount
                            .setHorizontalAlignment(SwingConstants.RIGHT);
                    jLblQuestionCount.setForeground(new java.awt.Color(0, 0,
                            255));
                }
                {
                    jLblPointsCount = new JLabel();
                    getContentPane().add(jLblPointsCount);
                    jLblPointsCount.setText("0");
                    jLblPointsCount.setBounds(192, 501, 38, 14);
                    jLblPointsCount
                            .setForeground(new java.awt.Color(0, 0, 255));
                    jLblPointsCount
                            .setHorizontalAlignment(SwingConstants.RIGHT);
                }
                {
                    jLblDiff = new JLabel();
                    getContentPane().add(jLblDiff);
                    jLblDiff.setText("1");
                    jLblDiff.setBounds(472, 473, 63, 14);
                    jLblDiff.setForeground(new java.awt.Color(0, 0, 255));
                }
                {
                    jBtnRemove = new JButton();
                    getContentPane().add(jBtnRemove);
                    jBtnRemove.setIcon(new ImageIcon(new ResourceHelper()
                            .getResourceBytes("/icons/remove.png")));
                    jBtnRemove.setHorizontalTextPosition(SwingConstants.CENTER);
                    jBtnRemove.setVerticalTextPosition(SwingConstants.BOTTOM);
                    jBtnRemove.setToolTipText("Odobra\u0165 otázku");
                    jBtnRemove.setBounds(528, 421, 21, 21);
                    jBtnRemove.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            jBtnRemoveActionPerformed(evt);
                        }
                    });
                }
                {
                    jBtnEditQuestion = new JButton();
                    getContentPane().add(jBtnEditQuestion);
                    jBtnEditQuestion.setIcon(new ImageIcon(new ResourceHelper()
                            .getResourceBytes("/icons/menuedit.png")));
                    jBtnEditQuestion
                            .setHorizontalTextPosition(SwingConstants.CENTER);
                    jBtnEditQuestion
                            .setVerticalTextPosition(SwingConstants.BOTTOM);
                    jBtnEditQuestion.setToolTipText("Upravi\u0165 otázku");
                    jBtnEditQuestion.setBounds(502, 421, 21, 21);
                    jBtnEditQuestion.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            jBtnEditQuestionActionPerformed(evt);
                        }
                    });
                }
                {
                    jBtnAddQuestion = new JButton();
                    // OP FIX: toto tlacitko sa na ziadost vrchnosti rusiii
                    //getContentPane().add(jBtnAddQuestion);
                    jBtnAddQuestion.setIcon(new ImageIcon(new ResourceHelper()
                            .getResourceBytes("/icons/add.png")));
                    jBtnAddQuestion
                            .setHorizontalTextPosition(SwingConstants.CENTER);
                    jBtnAddQuestion
                            .setVerticalTextPosition(SwingConstants.BOTTOM);
                    jBtnAddQuestion.setToolTipText("Prida\u0165 otázku");
                    jBtnAddQuestion.setBounds(476, 421, 20, 21);
                    jBtnAddQuestion.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            jBtnAddQuestionActionPerformed(evt);
                        }
                    });
                }
                {
                    jLabel5 = new JLabel();
                    getContentPane().add(jLabel5);
                    jLabel5.setText("Názov testu");
                    jLabel5.setBounds(12, 90, 79, 14);
                    jLabel5.setForeground(new java.awt.Color(100, 0, 0));
                }
                {
                    jLabel6 = new JLabel();
                    getContentPane().add(jLabel6);
                    jLabel6.setText("Predmet");
                    jLabel6.setBounds(12, 117, 79, 14);
                    jLabel6.setForeground(new java.awt.Color(100, 0, 0));
                }
                {
                    jTxtName = new JTextField();
                    getContentPane().add(jTxtName);
                    jTxtName.setBounds(103, 88, 446, 21);
                    jTxtName.setBackground(new java.awt.Color(255, 255, 240));
                    jTxtName.setForeground(new java.awt.Color(0, 0, 255));
                }
                {
                    jTxtSubject = new JTextField();
                    getContentPane().add(jTxtSubject);
                    jTxtSubject.setBounds(103, 114, 446, 21);
                    jTxtSubject
                            .setBackground(new java.awt.Color(255, 255, 240));
                    jTxtSubject.setForeground(new java.awt.Color(0, 0, 255));
                }
                {
                    jLabel7 = new JLabel();
                    getContentPane().add(jLabel7);
                    jLabel7.setText("Kategória");
                    jLabel7.setBounds(294, 500, 56, 15);
                    jLabel7.setForeground(new java.awt.Color(100, 0, 0));
                }
                {
                    jLblCategory = new JLabel();
                    getContentPane().add(jLblCategory);
                    jLblCategory.setBounds(363, 500, 173, 15);
                    jLblCategory.setForeground(new java.awt.Color(0, 0, 255));
                }
            }
            this.setSize(573, 621);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void hint(String text) {
        if (jTxtHint.getBackground() == GenexGUI.COMB1_BACKGROUND_COLOR) {
            jTxtHint.setBackground(GenexGUI.COMB2_BACKGROUND_COLOR);
            jTxtHint.setForeground(GenexGUI.COMB2_FOREGROUND_COLOR);
        } else {
            jTxtHint.setBackground(GenexGUI.COMB1_BACKGROUND_COLOR);
            jTxtHint.setForeground(GenexGUI.COMB1_FOREGROUND_COLOR);
        }
        if (text.startsWith("Error:")) {
            jTxtHint.setText(text.substring(6));
            jTxtHint.setCaretPosition(0);
            jTxtHint.insertIcon(new ImageIcon(resHelp
                    .getResourceBytes("/icons/error.png")));
        } else if (text.startsWith("Warning:")) {
            jTxtHint.setText(text.substring(8));
            jTxtHint.setCaretPosition(0);
            jTxtHint.insertIcon(new ImageIcon(resHelp
                    .getResourceBytes("/icons/warning.png")));
        } else if (text.startsWith("Info:")) {
            jTxtHint.setText(text.substring(5));
            jTxtHint.setCaretPosition(0);
            jTxtHint.insertIcon(new ImageIcon(resHelp
                    .getResourceBytes("/icons/info.png")));
        } else {
            jTxtHint.setText(text);
        }
    }

    private void jBtnOKActionPerformed(ActionEvent evt) {
        // TODO OK stlacene, update || pridanie noveho testu, treba dorobit!
        String name = jTxtName.getText().trim();
        if (name.length() == 0) {
            hint("Warning: Musíte zadať názov testu.");
            return;
        }

        ArrayList<QuestionPoints> qp = new ArrayList<QuestionPoints>(model
                .getQuestionCount());
        ArrayList<Question> q = model.getQuestions();
        ArrayList<Float> p = model.getPoints();

        for (int i = 0; i < q.size(); i++) {
            qp.add(new QuestionPoints(q.get(i).getQuestionID(), p.get(i)));
        }

        if (test == null)
            test = new Test();
        test.setName(name);
        test.setSubject(jTxtSubject.getText());
        test.setQuestionPoints(qp);
        test.setCategoryID(actualTestCategory.getCategoryID());
        test.setGenerated(new Timestamp(0));

        try {
            test.setUserID(new UserDaoDerby(ConnectionHelper.getConnection())
                    .getDefaultTUser().getUserID());
            TestDao td = new TestDaoDerby(ConnectionHelper.getConnection());
            if (test.getTestID() == null)
                td.addTest(actualTestCategory.getCategoryID(), test);
            else
                td.updateTest(test);
        } catch (SQLException e) {
            hint("Error: " + e.getMessage());
        }
        setVisible(false);
    }

    private void jBtnCancelActionPerformed(ActionEvent evt) {
        flag = true;
        setVisible(false);
    }

    private void jBtnItemsUpActionPerformed(ActionEvent evt) {
        questionsUp();
    }

    private void jBtnItemsDownActionPerformed(ActionEvent evt) {
        questionsDown();
    }

    private void jBtnReorderActionPerformed(ActionEvent evt) {
        reorder();
    }

    private void jBtnRemoveActionPerformed(ActionEvent evt) {
        deleteQuestions();
    }

    private void jBtnEditQuestionActionPerformed(ActionEvent evt) {
        editQuestion();
        genexModel.fireTableDataChanged();
    }

    private void jBtnAddQuestionActionPerformed(ActionEvent evt) {
        genex.requestFocus();
    }

    private void editQuestion() {
        int sel = jTblQuestions.getSelectedRow();
        if (sel == -1) {
            hint("Warning: Najprv vyberte otázku, ktorú chcete upraviť.");
            return;
        }

        try {
            Question question = model.getQuestion(sel);
            CategoryDao cd = new CategoryDaoDerby(ConnectionHelper
                    .getConnection());

            ArrayList<Category> arr_categories = new ArrayList<Category>();
            for (int cid : cd.getCategoriesIDByQuestionID(question
                    .getQuestionID())) {
                arr_categories.add(cd.getCategoryByID(cid));
            }

            System.out.println(question.getText());

            NewQuestionDialog nqd = new NewQuestionDialog(null, arr_categories,
                    question, ConnectionHelper.getConnection());
            nqd.setLocationRelativeTo(null);
            Question q = nqd.showDialog();
            if (q != null)
                model.setQuestion(q, sel);
            setStat();
        } catch (SQLException e) {
            hint("Error: " + e.getMessage());
        }
    }

    private void deleteQuestions() {
        int[] sel = jTblQuestions.getSelectedRows();
        if (sel.length == 0) {
            hint("Warning: Najprv vyberte otázky, ktorú chcete odstrániť.");
            return;
        }
        model.removeQuestions(sel);
        setStat();
    }

    private int[] echoMove() {
        int[] sel = jTblQuestions.getSelectedRows();
        if (sel.length == 0) {
            hint("Warning: Najprv vyberte otázky, ktorú chcete presunúť.");
            return null;
        }
        return sel;
    }

    private void questionsUp() {
        int[] sel = echoMove();
        if (sel == null || sel[0] == 0)
            return;
        for (int i = 0; i < sel.length; i++) {
            model.moveUp(sel[i]);
            sel[i]--;
        }
        select(sel);
    }

    private void questionsDown() {
        int[] sel = echoMove();
        if (sel == null || sel[sel.length - 1] == model.getQuestionCount() - 1)
            return;
        for (int i = sel.length - 1; i >= 0; i--) {
            model.moveDown(sel[i]);
            sel[i]++;
        }
        select(sel);
    }

    private void select(int[] sel) {
        for (int i = 0; i < sel.length; i++) {
            jTblQuestions.getSelectionModel().addSelectionInterval(sel[i],
                    sel[i]);
        }
    }

    private void reorder() {
        model.reorder();
    }

    public NewTestTableModel getModel() {
        return model;
    }

    public void setModel(NewTestTableModel model) {
        this.model = model;
    }

}
